<template>
	<view class="container">
		<view>
			<!-- <u-loading-icon text="花朵形"></u-loading-icon>
			<u-loading-icon mode="semicircle" text="半圆"></u-loading-icon>
			<u-loading-icon mode="circle" text="圆型"></u-loading-icon> -->
			<u-loading-icon :vertical="true"></u-loading-icon>
		</view>
	</view>
</template>

<script>
	import {
		uniGetToken
	} from '../../utils/common.js'
	export default {
		data() {
			return {

			}
		},
		onLoad() {
			this.getToken()
		},
		onShow() {
			console.log('进入onShow');
		},
		methods: {
			//中间件判断跳转路径
			getToken() {
				if (uniGetToken()) {
					console.log('TOKEN值2:', uniGetToken());
					uni.switchTab({
						url: '/pages/tabbar/work/index'
					})
				} else {
					console.log('TOKEN值1:', uniGetToken());
					uni.reLaunch({
						url: '/pages/login/index'
					})
				}
			},
			initNFC() {
				if (uni.getSystemInfoSync().platform == 'android') {
					listenNFCStatus();
				}
			},
			listenNFCStatus() {
				try {
					var main = plus.android.runtimeMainActivity();
					var Intent = plus.android.importClass('android.content.Intent');
					var PendingIntent = plus.android.importClass('android.app.PendingIntent');
					var IntentFilter = plus.android.importClass('android.content.IntentFilter');
					NfcAdapter = plus.android.importClass('android.nfc.NfcAdapter');
					var nfcAdapter = NfcAdapter.getDefaultAdapter(main);

					if (nfcAdapter == null) {
						uni.showToast({
							title: '设备不支持NFC！',
							icon: 'none'
						});
						return;
					}

					if (!nfcAdapter.isEnabled()) {
						uni.showToast({
							title: '请在系统设置中先启用NFC功能！',
							icon: 'none'
						});
						return;
					}

					var intent = new Intent(main, main.getClass());
					intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
					var pendingIntent = PendingIntent.getActivity(main, 0, intent, 0);
					var ndef = new IntentFilter("android.nfc.action.TECH_DISCOVERED");
					ndef.addDataType("*/*");
					var intentFiltersArray = [ndef];
					var techListsArray = [
						["android.nfc.tech.IsoDep"],
						["android.nfc.tech.NfcA"],
						["android.nfc.tech.NfcB"],
						["android.nfc.tech.NfcF"],
						["android.nfc.tech.NfcV"],
						["android.nfc.tech.NdefFormatable"],
						["android.nfc.tech.MifareClassic"],
						["android.nfc.tech.MifareUltralight"]
					];

					plus.globalEvent.addEventListener("newintent", function() {
						setTimeout(handle_nfc_data1, 1000);
					}, false);

					plus.globalEvent.addEventListener("pause", function(e) {
						if (nfcAdapter) {
							nfcAdapter.disableForegroundDispatch(main);
						}
					}, false);

					plus.globalEvent.addEventListener("resume", function(e) {
						if (nfcAdapter) {
							nfcAdapter.enableForegroundDispatch(main, pendingIntent, intentFiltersArray,
								techListsArray);
						}
					}, false);

					nfcAdapter.enableForegroundDispatch(main, pendingIntent, intentFiltersArray, techListsArray);
				} catch (e) {
					console.error(e);
				}
			}
		}
	}
</script>

<style scoped>
	.container {
		width: 100%;
		height: 100vh;
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
	}
</style>